package com.google.project.shared;

import java.util.Date;

import com.google.gwt.user.client.Window;
import com.sun.java.swing.plaf.windows.resources.windows;

public class CommonFuntion {

	@SuppressWarnings("deprecation")
	public static String convertToDate (Date input) {  

		return input.getDate() + "/" +(input.getMonth()+1)+ "/"+(input.getYear()+1900);
	}

	public static Boolean checkContain(String data,String check)
	{
		
		String [] list = data.split(",");
		for(String temp :list)
		{
			if(temp.equals(check))
			{
				return true;
			}
		}
		return false;
	}
	public static  Long removeTime(Date date)
	{
		int houseTime =date.getHours()*60 * 60 * 1000;
		int minusTime =date.getMinutes()*60  * 1000;
	    int secTime = date.getSeconds()*1000;
	    Long time = (date.getTime()/1000);
	    Long mili = date.getTime() - 1000*time.intValue();
	   
	    Long newDate = date.getTime()-houseTime - minusTime-secTime-mili.intValue();
	   // Window.alert(date.getTime()+"  "+ newDate+"^_^" +mili);
	    
		return newDate;
	}

	public static Double fomatNumber(Double data)
	{
		Double result =0d;
		result = data*100;
		result = result.intValue()+0d;
		result = result/100;
		return result;
	}
	/*
	 * Ham so sanh 2 ngay voi nhau: date1 and date2
	 * Ham tra ve gia tri integer voi y nghia sau:
	 * Neu date1 = date 2 => Tra ve ket qua = 0
	 * Neu date1 < date2 =>  Tra ve ket qua = 1
	 * Neu date1 > date2 =>  Tra ve ket qua = 2
	 */
	public static int compareWithTwoDay(Date date1, Date date2) {
		Long _date1 = removeTime(date1);
		Long _date2 = removeTime(date2);
		if(_date1 == _date2) {
			return 0;
		} else if(_date1 < _date2) {
			return 1;
		} else {
			return 2;
		}
	}
}
